home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2004 May / SGI IRIX 6.5 Applications 2004 May.iso / dist / java3d.idb / usr / demos / java / j3d / programs / examples / VirtualInputDevice / HelloUniverse.java.z / HelloUniverse.java
Encoding:
Java Source  |  2003-08-08  |  4.4 KB  |  130 lines

  1. /*
  2.  *    @(#)HelloUniverse.java 1.17 02/10/21 13:58:47
  3.  *
  4.  * Copyright (c) 1996-2002 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Redistribution and use in source and binary forms, with or without
  7.  * modification, are permitted provided that the following conditions
  8.  * are met:
  9.  *
  10.  * - Redistributions of source code must retain the above copyright
  11.  *   notice, this list of conditions and the following disclaimer.
  12.  *
  13.  * - Redistribution in binary form must reproduce the above copyright
  14.  *   notice, this list of conditions and the following disclaimer in
  15.  *   the documentation and/or other materials provided with the
  16.  *   distribution.
  17.  *
  18.  * Neither the name of Sun Microsystems, Inc. or the names of
  19.  * contributors may be used to endorse or promote products derived
  20.  * from this software without specific prior written permission.
  21.  *
  22.  * This software is provided "AS IS," without a warranty of any
  23.  * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
  24.  * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
  25.  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
  26.  * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
  27.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  28.  * DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
  29.  * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
  30.  * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
  31.  * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
  32.  * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE,
  33.  * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  34.  *
  35.  * You acknowledge that Software is not designed,licensed or intended
  36.  * for use in the design, construction, operation or maintenance of
  37.  * any nuclear facility.
  38.  */
  39.  
  40. import java.applet.Applet;
  41. import java.awt.*;
  42. import java.awt.event.*;
  43. import com.sun.j3d.utils.applet.MainFrame;
  44. import com.sun.j3d.utils.geometry.ColorCube;
  45. import com.sun.j3d.utils.universe.*;
  46. import javax.media.j3d.*;
  47. import javax.vecmath.*;
  48.  
  49. public class HelloUniverse extends Applet {
  50.  
  51.     private SimpleUniverse u = null;
  52.  
  53.     public BranchGroup createSceneGraph() {
  54.  
  55.     BranchGroup objRoot = new BranchGroup();
  56.     TransformGroup objTrans = new TransformGroup();
  57.     objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
  58.     objRoot.addChild(objTrans);
  59.     objTrans.addChild(new ColorCube(0.2));
  60.     Transform3D yAxis = new Transform3D();
  61.     Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE,
  62.                     0, 0,
  63.                     4000, 0, 0,
  64.                     0, 0, 0);
  65.     RotationInterpolator rotator =
  66.         new RotationInterpolator(rotationAlpha, objTrans, yAxis,
  67.                      0.0f, (float) Math.PI*2.0f);
  68.     BoundingSphere bounds =
  69.         new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
  70.     rotator.setSchedulingBounds(bounds);
  71.     objTrans.addChild(rotator);
  72.     return objRoot;
  73.     }
  74.  
  75.  
  76.     public HelloUniverse() {
  77.  
  78.     }
  79.  
  80.     public void init() {
  81.     // These are the string arguments given to the VirtualInputDevice
  82.         // constructor.  These are settable parameters.  Look in the 
  83.         // VirtualInputDevice constructor for a complete list.
  84.         String[] args = new String[10];
  85.         args[0] = "printvalues";
  86.         args[1] = "true";
  87.         args[2] = "yscreeninitloc";
  88.         args[3] = "50";
  89.         args[4] = null;
  90.  
  91.         InputDevice device = new VirtualInputDevice( args );
  92.  
  93.         // now create the HelloUniverse Canvas
  94.     setLayout(new BorderLayout());
  95.         GraphicsConfiguration config =
  96.            SimpleUniverse.getPreferredConfiguration();
  97.  
  98.         Canvas3D c = new Canvas3D(config);
  99.     add("Center", c);
  100.  
  101.     // Create a simple scene and attach it to the virtual universe
  102.     BranchGroup scene = createSceneGraph();
  103.     u = new SimpleUniverse(c);
  104.  
  105.         // The InputDevice must be initialized before registering it 
  106.         // with the PhysicalEnvironment object.
  107.         device.initialize();
  108.  
  109.     // Register the VirtualInputDevice with Java 3D
  110.     u.getViewer().getPhysicalEnvironment().addInputDevice( device );
  111.  
  112.     TransformGroup viewTrans = 
  113.                         u.getViewingPlatform().getViewPlatformTransform();
  114.     SensorBehavior s = new SensorBehavior( viewTrans, device.getSensor(0) );
  115.     s.setSchedulingBounds( new BoundingSphere
  116.                        ( new Point3d(0.0,0.0,0.0), Float.MAX_VALUE ));
  117.     scene.addChild( s );
  118.     u.addBranchGraph(scene);
  119.     }
  120.  
  121.     public void destroy() {
  122.     u.cleanup();
  123.     }
  124.  
  125.  
  126.     public static void main(String[] args) {
  127.     new MainFrame(new HelloUniverse(), 350, 350);
  128.     }
  129. }
  130.